"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class File extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
      models.File.belongsTo(models.User, { foreignKey: "userId", as: "user" });
    }
  }
  File.init(
    {
      originalname: DataTypes.STRING,
      filename: {
        type: DataTypes.STRING,
        allowNull: false,
        validate: {
          notNull: "不能为null",
          notEmpty: "不能为空",
        },
      },
      fullName: DataTypes.STRING,
      userId: DataTypes.INTEGER,
      size: DataTypes.INTEGER,
      mimetype: DataTypes.STRING,
      url: DataTypes.STRING,
      path: DataTypes.STRING,
    },
    {
      sequelize,
      modelName: "File",
    }
  );
  return File;
};
